from sqlalchemy import Column, DateTime, Enum, Integer, String, func
from sqlalchemy.orm import relationship

from app.database.models.base import Base


class VPNServer(Base):
    __tablename__ = "vpn_server"

    id = Column(Integer, primary_key=True)
    status = Column(Enum("active", "inactive"), server_default="active")
    name = Column(String(255))
    description = Column(String(255))
    ip_address = Column(String(100), nullable=False)
    ssh_port = Column(Integer, nullable=False)
    login = Column(String(100), nullable=False)
    password = Column(String(100), nullable=False)
    orders = relationship("Order", back_populates="vpn_server")
    was_added = Column(DateTime, server_default=func.now())

    def __str__(self):
        return self.ip_address

    def __repr__(self):
        return f"<VPN Server №{self.id} {self.ip_address}>"
